﻿using FlowDesigner.HelperVision;
using FlowDesigner.INotifyCommadBase;
using FlowDesigner.Interfacebase;
using FlowDesigner.Models;
using FlowDesigner.View;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using Unity;
using FlowDesigner.Listpicker.ListpickerView;
using FlowDesigner.Listpicker.ListpickerViewModel;

namespace FlowDesigner.ViewModel
{
    public class EditflownodeViewModel: NotifyBase, IBaseDialogViewModel
    {

        public EditflownodeViewModel()
        {
            initialize();
        }

        public event Func<object> MethodCalled;

        private void selectcommand_(string obj)
        {
            commandList[obj]?.Invoke();
        }
        public ParameterCommand<string> selectcommand { get; set; }
        private Dictionary<string,Action> commandList {  get; set; }
        public flownodeEditModel Interactionmodel { get;set; }
        /// <summary>
        /// 初始化 
        /// </summary>
        private bool initialize()
        {
            Interactionmodel = new flownodeEditModel();
            selectcommand = new ParameterCommand<string>(selectcommand_);
            commandList = new Dictionary<string, Action>();
            // 获取当前类的所有 public 和 private 方法
            MethodInfo[] methods = this.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            //挂载方法
            foreach (var method in methods)
            {
                // 获取方法的 Description 特性（如果存在）
                var descriptionAttribute = method.GetCustomAttribute<DescriptionAttribute>();

                if (descriptionAttribute != null)
                {
                    // 获取方法的描述
                    string description = descriptionAttribute.Description;
                    if(description.Contains("command"))
                    {
                        // 将方法转换为 Action 并保存到字典
                        Action methodAction = (Action)Delegate.CreateDelegate(typeof(Action), this, method);
                        // 将方法的描述作为键，方法的 Action 委托作为值存储到字典中
                        commandList[description] = methodAction;
                    }
                }
            }
            return true;
        }
        /// <summary>
        /// 选择录入人
        /// </summary>
        [Description("selectEntrantcommand")]
        private void selectEntrantcommand()
        {
            BaseDialogViewModel mainViewModel = Containerfot.Container.container.Resolve<BaseDialogViewModel>();
            mainViewModel.ShowDialog(typeof(SelectEntrantlistview), typeof(SelectEntrantlistviewModel), o =>
            {

            },
            null
            );
        }
        /// <summary>
        /// 选择执行角色
        /// </summary>
        [Description("selectPerformrolecommand")]
        private void selectPerformrolecommand()
        {

        }
        /// <summary>
        /// 选择执行部门
        /// </summary>
        [Description("selectDepartmentcommand")]
        private void selectDepartmentcommand()
        {

        }
        /// <summary>
        /// 输入执行条件
        /// </summary>
        [Description("selectExecutivecommand")]
        private void selectExecutivecommand()
        {

        }
        /// <summary>
        /// 需要返回的参数
        /// </summary>
        /// <returns></returns>
        public object returnData()
        {
            return Interactionmodel;
        }
        /// <summary>
        /// 接受传过来的值
        /// </summary>
        /// <param name="o"></param>
        public void Passparameters(object o)
        {
            var passdata = o as FloWTask;
            if(passdata is FloWTask)
            {
                Tool.MapProperties(o, Interactionmodel);
                //Interactionmodel.Timeoutexecution = passdata.Timeoutexecution;
                //Interactionmodel.Description = passdata.Description;
                //Interactionmodel.ExecutiveDepartment = passdata.ExecutiveDepartment;
                //Interactionmodel.branch = passdata.Branch;
                //Interactionmodel.Executionconditions = passdata.Executionconditions;
                //Interactionmodel.Entrant = passdata.Entrant;
                //Interactionmodel.Performrole = passdata.Performrole;
            }
        }
    }
}
